﻿using System;
using System.Text;
using TI_BLE_HCI_ClientLib.BaseEntities;
using TI_BLE_HCI_ClientLib.GenericHCIEntities;
using TI_BLE_HCI_ClientLib.HCIBaseEntities;

namespace TI_BLE_HCI_ClientLib.HCICommands
{
    public class HCICommand_GAP_Make_Discoverable : HCIVendorSpecificCommand
    {
        private const byte CMD = 0x6;

        public enum EventTypeEnum
        {
            ConnectableUndirectedAdvertisement=0,
            ConnectableDirectedAdvertisement = 1,
            DiscoverableUndirectedAdvertisement = 2,
            NonConnectableUndirectedAdvertisement = 3
        }

        public enum InitiatorAddrTypeEnum
        {
            ADDRTYPE_PUBLIC=0,
            ADDRTYPE_STATIC = 1,
            ADDRTYPE_PRIVATE_NONRESOLVE=2,
            ADDRTYPE_PRIVATE_RESOLVE = 3
        }

        [Flags]
        public enum ChannelMapEnum
        {
            Channel37=1,
            Channel38=2,
            Channel39=4
        }

        public enum FilterPolicyEnum
        {
            AllowScanFromAnyAllowConnectRequestFromAny=0,
            AllowScanFromWhiteListAllowConnectRequestFromAny = 1,
            AllowScanFromAnyAllowConnectRequestFromWhiteList = 2,
            AllowScanFromWhiteListAllowConnectRequestFromWhiteList = 3
        }

        public enum Return_Status
        {
            Success = 0,
            AdvertisingDataNotSetup = 0x10,
            NotAvailableAtThisTime=0x11,
            InvalidProfileRole=0x12
        }

        public HCICommand_GAP_Make_Discoverable(EventTypeEnum eventType, InitiatorAddrTypeEnum initiatorAddrType,
            byte[] initiatorAddr, ChannelMapEnum channelMap, FilterPolicyEnum filterPolicy) : base(HCIVendorSpecificCommandCSG.GAP, CMD)
        {
            var pars = new BaseEntityParameter[5];

            pars[0] = new ByteParameter((byte)eventType);
            pars[1] = new ByteParameter((byte)initiatorAddrType);
            pars[2] = new ByteArrayParameter(initiatorAddr);
            pars[3] = new ByteParameter((byte)channelMap);
            pars[4] = new ByteParameter((byte)filterPolicy);

            base.addParameters(pars);
        }
    }
}
